package org.example.springbook.model;

import lombok.Data;

@Data
public class Result<T> {
    private int code;
    private String msg;
    private T data;

    // 成功
    public static <T> Result<T> success(T data) {
        Result<T> result = new Result<>();
        result.setCode(200);
        result.setMsg("success");
        result.setData(data);
        return result;
    }
    //失败
    public static <T> Result<T> error(String msg) {
        Result<T> result = new Result<>();
        result.setCode(-1);
        result.setMsg(msg);
        return result;
    }
    public static <T> Result<T> error(String msg, T data) {
        Result<T> result = new Result<>();
        result.setCode(-1);
        result.setMsg(msg);
        result.setData(data);
        return result;
    }

    // 未登录
    public static <T> Result<T> unlogin() {
        Result<T> result = new Result<>();
        result.setCode(-2);
        result.setMsg("用户未登录，请登录！");
        return result;
    }




}
